package com.ebt.m.homepage;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import com.ebt.m.R;
import com.ebt.m.commons.buscomponent.listview.BaseListView;
import com.ebt.m.commons.buscomponent.listview.ISectionFactory;
import com.ebt.m.commons.buscomponent.listview.IView;
import com.ebt.m.presenter.OpportunityPresenter;
import com.ebt.m.view.timeline.SectionAlertView;
import com.ebt.m.view.timeline.SectionCloudMsgView;
import com.ebt.m.view.timeline.SectionOpportunityView;


public class OpportunityContentView extends BaseListView<OpportunityPresenter> {


    public OpportunityContentView(Context context) {
        this(context, null);
    }

    public OpportunityContentView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public OpportunityContentView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public IView.OnClickListner onClickListner = new IView.OnClickListner() {
        @Override
        public void onClick(View view, Object... args) {
            switch (view.getId()) {
                case R.id.item_root:
                    mPresenter.readMessage((int) args[0]);
                    break;
            }
        }

        @Override
        public void onLongClick(View view, Object... args) {

        }
    };

    @Override
    protected ISectionFactory createViewFactory() {
        ISectionFactory factory = viewType -> {
            if (viewType == OpportunityPresenter.TYPE_PROPOSAL) {
                SectionOpportunityView opportunityView = new SectionOpportunityView(getContext());
                opportunityView.setOnClickViewListener(onClickListner);
                return opportunityView;
            } else if (viewType == OpportunityPresenter.TYPE_ALERT) {
                SectionAlertView sectionAlertView = new SectionAlertView(getContext());
                sectionAlertView.setOnClickViewListener(onClickListner);
                return sectionAlertView;
            } else if (viewType == OpportunityPresenter.TYPE_CLOUD) {
                SectionCloudMsgView opportunityView = new SectionCloudMsgView(getContext());
                opportunityView.setOnClickViewListener(onClickListner);
                return opportunityView;
            } else {
                return null;
            }
        };
        return factory;
    }

    @Override
    protected OpportunityPresenter createPresenter() {
        return new OpportunityPresenter(getContext(), this);
    }

    @Override
    protected View configEmptyView() {
        View emptyContent = LayoutInflater.from(getContext()).inflate(R.layout.layout_opportunity_empty, null);
        return emptyContent;
    }

    @Override
    public void loadNext() {
        mPresenter.loadNext();
    }

    @Override
    public void update(Object... args) {
        super.update(args);
        mPresenter.loadNew(args);
    }

    @Override
    protected boolean createFootView() {
        return true;
    }
}
